sad:
	@ args = 0, pretend = 0, frame = 32
	@ frame_needed = 1, uses_anonymous_args = 0
	mov	ip, sp
	stmfd	sp!, {fp, ip, lr, pc}
	sub	fp, ip, #4
	sub	sp, sp, #32
	str	r0, [fp, #-16]	// Store x
	str	r1, [fp, #-20]	// Store y
	str	r2, [fp, #-24] // Store r
	str	r3, [fp, #-28] // Store s
	mov	r3, #0			// sad = 0
	str	r3, [fp, #-32] // Store sad
	mov	r3, #0			// i = 0
	str	r3, [fp, #-40] // Store i
.L2:
	ldr	r3, [fp, #-40] // Determine to break outer loop
	cmp	r3, #15
	bgt	.L3
	mov	r3, #0			// j = 0
	str	r3, [fp, #-44] // Store j
.L5:
	ldr	r3, [fp, #-44] // Determine to break inner loop
	cmp	r3, #15
	bgt	.L4
	ldr	r1, .L10			// Determine pixel index for frameA
	ldr	r2, [fp, #-16] 
	ldr	r3, [fp, #-40]
	add	r2, r2, r3
	mov	r3, r2
	mov	r3, r3, asl #2
	add	r3, r3, r2
	mov	r2, r3, asl #7
	ldr	r3, [fp, #-20]
	add	r2, r2, r3
	ldr	r3, [fp, #-44]
	add	r0, r2, r3
	ldr	ip, .L10+4		// Determine pixel index for frameB
	ldr	r2, [fp, #-16]
	ldr	r3, [fp, #-40]
	add	r2, r2, r3
	ldr	r3, [fp, #-24]
	add	r2, r2, r3
	mov	r3, r2
	mov	r3, r3, asl #2
	add	r3, r3, r2
	mov	r2, r3, asl #7
	ldr	r3, [fp, #-20]
	add	r2, r2, r3
	ldr	r3, [fp, #-28]
	add	r2, r2, r3
	ldr	r3, [fp, #-44]
	add	r3, r2, r3
	ldr	r2, [r1, r0, asl #2] // Load pixel for frameA
	ldr	r3, [ip, r3, asl #2] // Load pixel for frameB
	rsb	r3, r3, r2				// diff = pixelA - pixelB
	str	r3, [fp, #-36] // Determine the SAD
	ldr	r2, [fp, #-32]
	ldr	r3, [fp, #-36]
	add	r3, r2, r3
	str	r3, [fp, #-32]	// Store SAD
	ldr	r3, [fp, #-44] // j++
	add	r3, r3, #1
	str	r3, [fp, #-44]
	b	.L5
.L4:
	ldr	r3, [fp, #-40] // i++
	add	r3, r3, #1
	str	r3, [fp, #-40]
	b	.L2
.L3:
	ldr	r3, [fp, #-32]	// return SAD
	mov	r0, r3   
	sub	sp, fp, #12		
	ldmfd	sp, {fp, sp, pc} // exit SAD
.L11:
	.align	2
.L10:
	.word	frameA
	.word	frameB

